<?php
/**
 * Created by PhpStorm.
 * User: tommy
 * Date: 2018/6/15
 * Time: 10:31
 */

namespace frontend\service;
use common\models\info\Album;
use common\utils\CommonUtil;

class TravelService
{

    /****
     * 获取旅行照
     */
    public static function getTravelPhoto(){
        $page = \Yii::$app->request->get("page",1);
        $pageSize = \Yii::$app->request->post("pageSize",15);
        $key = "travel:photo";
        $data = CommonUtil::getCache(__CLASS__,$key);
        if(!$data){
            $result = Album::getAllList('',$page,$pageSize);
            if (count($result["rows"])) {
                foreach ($result["rows"] as $key=>$val) {
                    $result['rows'][$key]['link'] =  CommonUtil::generateUrl($val['id'],'album');
                    $result["rows"][$key]["created_at"] = date("Y-m-d",$val["created_at"]);
                }
            }
            CommonUtil::setCache(__CLASS__,$key,$result,3600);
        }
        return $result;
    }

}

